package com.atguigu.juc.study.chapter05.locksupport.sync;

import java.util.concurrent.TimeUnit;

/**
 *
 *  wait()和notify()/notifyAll():必须与同步监视器一起使用，否则会抛出异常
 *
 * @author : leimingchao
 * @date Date : 2022年06月12日 20:31
 */
public class LockSupportDemo2 {

    public static void main(String[] args) {

        Object object = new Object();

        new Thread(() -> {

            // synchronized (object) {
                System.out.println(Thread.currentThread().getName() + "\t ----come in");

                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "\t ----被唤醒");
            // }

        }, "t1").start();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            // synchronized (object) {
                object.notify();
                System.out.println(Thread.currentThread().getName() + "\t ----发出通知");
            // }
        }, "t2").start();
    }
}
